/*
Rilego - An easy Images 2 E-Book converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package it.kirys.rilego.gui;

import java.awt.BorderLayout;
import java.net.URL;
import javax.help.HelpSet;
import javax.help.JHelp;

/**
 *
 * @author Federico Improta
 */
public class HelpFrame extends javax.swing.JFrame {

	JHelp helpViewer = null;
	private static final String PATH_TO_JAVA_HELP = "/guihelp/rilegogui.hs";

	private static HelpFrame hFrame=null;
	/** Creates new form HelpFrame */
	public HelpFrame() {
		initComponents();
		initHelp();
	}

	private void initHelp() {
		try {
			// Get the classloader of this class.
			ClassLoader cl = HelpFrame.class.getClassLoader();
			// Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
			// Note that in this example the location of the helpset is implied as being in the same
			// directory as the program by specifying "jhelpset.hs" without any directory prefix,
			// this should be adjusted to suit the implementation.
			URL url = HelpSet.findHelpSet(cl, PATH_TO_JAVA_HELP);
			url=this.getClass().getResource(PATH_TO_JAVA_HELP);

			// Create a new JHelp object with a new HelpSet.
			helpViewer = new JHelp(new HelpSet(cl, url));
			// Set the initial entry point in the table of contents.
		} catch (Exception e) {
			System.err.println("API Help Set not found");
		}
		this.setSize(800,600);
      this.getContentPane().add(helpViewer, BorderLayout.CENTER);
      // Set a default close operation.
	}

	public  static void showHelp(String reference) {
		if (hFrame==null){
			hFrame = new HelpFrame();
		}
		hFrame.setVisible(true);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      setTitle("Rilego help");
      setMinimumSize(new java.awt.Dimension(350, 350));
      addWindowListener(new java.awt.event.WindowAdapter() {
         public void windowClosed(java.awt.event.WindowEvent evt) {
            formWindowClosed(evt);
         }
      });

      pack();
   }// </editor-fold>//GEN-END:initComponents

	private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
		hFrame=null;
	}//GEN-LAST:event_formWindowClosed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   // End of variables declaration//GEN-END:variables
}
